import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _class, _class2;

/**
 * System - 系统配置
 * @date: 2019-11-1

 * @version: 1.0.0
 */
import React, { Component } from 'react';
import { Col, Form, Input, Row } from 'antd';
import { Bind } from 'lodash-decorators';
import Switch from 'components/Switch';
import intl from 'utils/intl';
var FormItem = Form.Item;
var formLayout = {
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 18
  }
};
var System = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
  _inherits(System, _Component);

  var _super = _createSuper(System);

  function System(props) {
    var _this;

    _classCallCheck(this, System);

    _this = _super.call(this, props);
    _this.state = {};
    return _this;
  }

  _createClass(System, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          getFieldDecorator = _this$props.form.getFieldDecorator,
          _this$props$config$da = _this$props.config.data,
          data = _this$props$config$da === void 0 ? [] : _this$props$config$da,
          isSite = _this$props.isSite;
      var password = this.findConfigField('CIAM.IF_SEND_MODIFY_PASSWORD', data);
      var sendFlag = this.findConfigField('CIAM.IF_SEND_CREATE_USER', data);
      var url = this.findConfigField('CIAM.INDEX_URL', data);
      return /*#__PURE__*/React.createElement(Form, null, isSite && /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.url').d('发送信息首页地址链接')
      }, formLayout), getFieldDecorator('url', {
        initialValue: url,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.url').d('发送信息首页地址链接')
          })
        } // {
        //   max: 80,
        //   message: intl.get('cpaas.common.validation.max', { max: 80 }),
        // },
        ]
      })( /*#__PURE__*/React.createElement(Input, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.password').d('修改密码是否发送消息')
      }, formLayout), getFieldDecorator('password', {
        initialValue: password === '1' ? 1 : 0
      })( /*#__PURE__*/React.createElement(Switch, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.sendFlag').d('创建用户是否发送消息')
      }, formLayout), getFieldDecorator('sendFlag', {
        initialValue: sendFlag === '1' ? 1 : 0
      })( /*#__PURE__*/React.createElement(Switch, null))))));
    }
    /**
     * 从配置列表查找配置项
     * @param {Number|String} field 查询配置字段的 ID 或 Code
     * @param {Array} data 获取到的原配置数组
     */

  }, {
    key: "findConfigField",
    value: function findConfigField(field, data) {
      if (data.length > 0) {
        var dataFilter = data.find(function (item) {
          return item.configCode === field;
        });
        return dataFilter ? dataFilter.configValue : null;
      }
    }
  }]);

  return System;
}(Component), (_applyDecoratedDescriptor(_class2.prototype, "findConfigField", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "findConfigField"), _class2.prototype)), _class2)) || _class);
export { System as default };